﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Marmat.Forms.Skin
{
    partial class SkinButton
    {

        /// <summary>
        /// 获取或设置控件的前景色。
        /// </summary>
        public override Color ForeColor
        {
            get
            {
                Color result = System.Windows.Forms.Control.DefaultForeColor;
                if (this._foreColor != default)
                    result = this._foreColor;
                else
                {
                    switch (this.ThemeStyle)
                    {
                        case ThemeStyleEnum.Default:
                            result = Configuration.DefaultTheme.RegularText;
                            break;
                        case ThemeStyleEnum.Primary:
                        case ThemeStyleEnum.Success:
                        case ThemeStyleEnum.Info:
                        case ThemeStyleEnum.Warning:
                        case ThemeStyleEnum.Danger:
                            result = Color.White;
                            break;
                    }
                }
                return result;
            }
            set => this._foreColor = value;
        }
        private Color _foreColor = Color.Empty;

        #region 圆角的程度
        /// <summary>
        /// 按钮的圆角程度（不能超过控件高度的一半）。
        /// </summary>
        [Category("样式"), Description("按钮的圆角程度（不能超过控件高度的一半）。")]
        [DefaultValue(0)]
        public int Circle
        {
            get => this._circle;
            set
            {
                if (this._circle != value)
                {
                    if (value > this.Height / 2)
                        this._circle = this.Height / 2;
                    else
                        this._circle = value;
                    this.Invalidate();
                }
            }
        }
        private int _circle;
        #endregion

        /// <summary>
        /// 是否开启圆角按钮，如果为true则 Circle 属性设置无效
        /// </summary>
        [Category("样式"), Description("是否开启圆角按钮，如果为true则 Circle 属性设置无效")]
        [DefaultValue(false)]
        public bool Round
        {
            get => this.round;
            set
            {
                if (this.round != value)
                {
                    this.round = value;
                    this.Invalidate();
                }
            }
        }
        private bool round;

        /// <summary>
        /// 是否加载中状态。
        /// </summary>
        [Category("样式"), Description("是否加载中状态。")]
        [DefaultValue(false)]
        public bool Loading
        {
            get => this.loading;
            set
            {
                if (this.loading == value)
                    return;
                this.loading = value;
                if (value)
                {
                    this.Enabled = false;
                    if (ImageAnimator.CanAnimate(loadIcon))
                    {
                        lock (loadIcon)
                        {
                            ImageAnimator.Animate(loadIcon, (sender, _) =>
                            {
                                ImageAnimator.UpdateFrames(loadIcon);
                                this.Invalidate();
                            });
                        }
                    }
                }
                else
                {
                    this.Enabled = true;
                    this.Invalidate();
                }
            }
        }
        private bool loading;
        private Image loadIcon = Properties.Resources.btn_loding;

        /// <summary>
        /// 按钮的背景色
        /// </summary>
        public new Color BackColor
        {
            get
            {
                Color result = this._backColor;
                if (result == default)
                {
                    switch (this.ThemeStyle)
                    {
                        case ThemeStyleEnum.Default:
                            result = Color.White;
                            break;
                        case ThemeStyleEnum.Primary:
                            result = Configuration.DefaultTheme.Primary;
                            break;
                        case ThemeStyleEnum.Success:
                            result = Configuration.DefaultTheme.Success;
                            break;
                        case ThemeStyleEnum.Info:
                            result = Configuration.DefaultTheme.Info;
                            break;
                        case ThemeStyleEnum.Warning:
                            result = Configuration.DefaultTheme.Warning;
                            break;
                        case ThemeStyleEnum.Danger:
                            result = Configuration.DefaultTheme.Danger;
                            break;
                    }
                }
                return result;
            }
            set
            {
                _backColor = value;
                this.Invalidate();
            }
        }
        private Color _backColor;

        #region 按钮的显示文本
        /// <summary>
        /// 获取或设置与此控件关联的文本。
        /// </summary>
        [Category("样式"), Description("获取或设置与此控件关联的文本。")]
        [DefaultValue("")]
        public override string Text { get; set; }
        #endregion

        #region 默认Size
        /// <summary>
        /// 默认大小
        /// </summary>
        protected override Size DefaultSize => new Size(75, 23);
        #endregion

        /// <summary>
        /// 获取或设置按钮的显示图像。
        /// </summary>
        [Category("样式"), Description("获取或设置按钮的显示图像。")]
        [DefaultValue(null)]
        public Image Image { get; set; }


        /// <summary>
        /// 获取或设置组件的主题样式。
        /// </summary>
        [Category("样式"), Description("获取或设置组件的主题样式。")]
        [DefaultValue(typeof(ThemeStyleEnum), nameof(ThemeStyleEnum.Primary))]
        public ThemeStyleEnum ThemeStyle
        {
            get => _themeStyle;
            set
            {
                if (this._themeStyle != value)
                {
                    this._themeStyle = value;
                    this.Invalidate();
                }
            }
        }
        private ThemeStyleEnum _themeStyle = ThemeStyleEnum.Primary;

        /// <summary>
        /// 图标在右边显示,此属性只有在同时显示Text与Icon时有效
        /// </summary>
        [Category("样式"), Description("图标在右边显示,此属性只有在同时显示Text与Icon时有效")]
        [DefaultValue(true)]
        public bool IconOnRight
        {
            get => _iconOnRight;
            set
            {
                this._iconOnRight = value;
                this.Invalidate();
            }
        }
        private bool _iconOnRight = true;

        /// <summary>
        /// 获取或设置是否为朴素按钮。
        /// </summary>
        [DefaultValue(false)]
        [Category("样式"), Description("获取或设置是否为朴素按钮。")]
        public bool Plain { get; set; }
    }
}
